package cn.bigfire.wzdj.cron;

import cn.bigfire.wzdj.frame.WZDJMainFrame;
import cn.bigfire.wzdj.service.WZDJService;
import cn.bigfire.wzdj.util.Stores;
import io.netty.util.internal.ThrowableUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WZDJCron {

    private static final Logger log = LoggerFactory.getLogger(WZDJCron.class);

    //1秒1次
    public static void second() {
        try {
            WZDJService.jobTime();//更新数显
            WZDJService.jobEnergy();//更新体力
            WZDJService.jobFightUI();//战斗页面 更新战斗信息
        } catch (Exception e) {
            log.error("1秒1次 second error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }
    // 5秒1次
    public static void fightAuto(){
        try {
            WZDJService.jobCheckQRExpire();//检测登录二维码状态
            WZDJService.jobAutoFight();    //检查战斗状态，判断师傅需要召唤，卖出，等
        } catch (Exception e) {
            log.error("5秒1次 fightAuto error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }
    // 20秒1次
    public static void checkStatus(){
        try {
            WZDJService.jobStartFight();//检查挂机模式
            WZDJService.jobHomeChat();//定频聊天
        } catch (Exception e) {
            log.error("20秒1次 checkStatus error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }


    //1分1次，查看是否有需要执行的代码
    public static void minute(){
        try {
            //ServerCheck.serverExec();//服务器命令
            //WZDJService.jobHomeChannel();//大厅掉线,重连
        } catch (Exception e) {
            log.error("1分1次 minute error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }


    //1时次
    public static void hour() {
        try {
            WZDJService.jobHomeChannel();//大厅掉线,重连
            Stores.getWzdjMainFrame().goldBuyGoods();//商店购买商品
            WZDJMainFrame.handlerRecruitClick(1);//招募10 抽3次。方便每天进度120%
        } catch (Exception e) {
            log.error("1时次 hour error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }

    //1天3次
    public static void autoGainAward(){
        try {
            Stores.getWzdjMainFrame().handleGainAwardClick();//一键领奖 领取奖励
        } catch (Exception e) {
            log.error("1天3次 autoGainAward error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }

    //1天1次
    public static void dayChange(){
        try {
            Stores.getInstance().dayChange();//每天清理战斗状态
        } catch (Exception e) {
            log.error("1天1次 dayChange error:{}", ThrowableUtil.stackTraceToString(e));
        }
    }



}
